﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace QunYing.DAL
{
	/// <summary>
	/// 数据访问类:GoodsImg
	/// </summary>
	public partial class GoodsImg
	{
        /// <summary>
        /// 商品图片
        /// </summary>
        public DataTable GetGoodsImg(string id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM dbo.GoodsImg WHERE 商品ID='"+id+"' ORDER BY 默认图片 DESC");
            return DbHelperSQL.Query(strSql.ToString()).Tables[0];
        }

        /// <summary>
        /// 商品图片
        /// </summary>
        public DataTable GetGoodsImgByCache(string id)
        {
            string CacheKey = "GetGoodsImg-" + id;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = GetGoodsImg(id);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (DataTable)objModel;
        }


        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string id,string paths)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from GoodsImg ");
            strSql.Append(" where 商品ID='" + id + "' and 图片路径 in (" + paths + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
	}
}

